package com.zxy.controller;

import com.zxy.common.result.Result;
import com.zxy.pojo.dto.*;
import com.zxy.pojo.entity.Clue;
import com.zxy.pojo.entity.CourseContract;
import com.zxy.pojo.vo.*;
import com.zxy.pojo.vo.VulnerabilityMapResponseVO;
import com.zxy.service.ReportService;
import com.zxy.util.OperLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.HashMap;
import java.util.List;

//统计分析模块
@RestController
@RequestMapping("/report")
public class ReportController {
    @Autowired
    private ReportService reportService;

    //客户统计列表展示
    @OperLog(title = "客户统计列表展示",businessType = 0,saveParams = true,saveResult = true)
    @GetMapping("/contractStatisticsList")
    public CourseContractResponseVO<CourseContract> contractStatisticsList(CustomerDTO dto) {
        return reportService.contractStatisticsList(dto);
    }

    //客户统计数据表
    @OperLog(title = "客户统计数据表",businessType = 0)
    @GetMapping("/contractStatistics/{beginCreateTime}/{endCreateTime}")
    public ReportVo contractStatistics(@PathVariable("beginCreateTime") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginCreateTime,
                                       @PathVariable("endCreateTime") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endCreateTime) {

        return reportService.contractStatistics(beginCreateTime, endCreateTime);
    }

    //学科客户分布
    @OperLog(title = "学科客户分布",businessType = 0)
    @GetMapping("/subjectStatistics/{beginCreateTime}/{endCreateTime}")
    public ReportSubjectDTO subjectStatistics(@PathVariable("beginCreateTime") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginCreateTime,
                                              @PathVariable("endEndTime") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endCreateTime) {

        return reportService.subjectStatistics(beginCreateTime, endCreateTime);
    }

    //销售列表展示 归属部门
    @OperLog(title = "销售列表展示",businessType = 0)
    @GetMapping("/deptStatisticsList/{pathStartDate}/{pathEndDate}")
    public CourseContractResponseVO<deptStatisticsListVo> deptStatisticsList(
            @PathVariable("pathStartDate")
            @DateTimeFormat(pattern = "yyyy-MM-dd")
            LocalDate pathStartDate,
            @PathVariable("pathEndDate")
            @DateTimeFormat(pattern = "yyyy-MM-dd")
            LocalDate pathEndDate, PageDTO dto) {
        return reportService.deptStatisticsList(pathStartDate, pathEndDate, dto);
    }

    //销售列表展示 归属人
    @OperLog(title = "销售列表展示",businessType = 0)
    @GetMapping("/ownerShipStatisticsList/{pathStartDate}/{pathEndDate}")
    public CourseContractResponseVO<deptStatisticsListVo> ownerShipStatisticsList(
            @PathVariable("pathStartDate")
            @DateTimeFormat(pattern = "yyyy-MM-dd")
            LocalDate pathStartDate,
            @PathVariable("pathEndDate")
            @DateTimeFormat(pattern = "yyyy-MM-dd")
            LocalDate pathEndDate, PageDTO dto) {
        return reportService.ownerShipStatisticsList(pathStartDate, pathEndDate, dto);
    }

    //销售列表 归属渠道
    @OperLog(title = "销售列表 ",businessType = 0)
    @GetMapping("/channelStatisticsList/{pathStartDate}/{pathEndDate}")
    public CourseContractResponseVO<deptStatisticsListVo> channelStatisticsList(
            @PathVariable("pathStartDate")
            @DateTimeFormat(pattern = "yyyy-MM-dd")
            LocalDate pathStartDate,
            @PathVariable("pathEndDate")
            @DateTimeFormat(pattern = "yyyy-MM-dd")
            LocalDate pathEndDate, PageDTO dto) {
        return reportService.channelStatisticsList(pathStartDate, pathEndDate, dto);
    }

    //销售统计
    @OperLog(title = "销售统计 ",businessType = 0)
    @GetMapping("/salesStatistics/{beginCreateTime}/{endCreateTime}")
    public ReportVo salesStatistics(
            @PathVariable("beginCreateTime") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginCreateTime,
            @PathVariable("endCreateTime") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endCreateTime) {
        return reportService.salesStatistics(beginCreateTime, endCreateTime);
    }

    //线索统计 分页展示
    @OperLog(title = "线索统计 ",businessType = 0)
    @GetMapping("/cluesStatisticsList")
    public CourseContractResponseVO<ClueDetailVo> cluesStatistics(CluesPageNumDTO dto) {
        return reportService.cluesStatistics(dto);
    }


    /**
     * 获取漏洞统计地图数据
     *
     * @param beginDate 开始日期
     * @param endDate   结束日期
     * @return 统计结果
     */
    @OperLog(title = "获取漏洞统计地图数据",businessType = 0)
    @GetMapping("/getVulnerabilityMap/{beginDate}/{endDate}")
    public VulnerabilityMapResponseVO getVulnerabilityMap(
            @PathVariable("beginDate") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginDate,
            @PathVariable("endDate") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate) {
        return reportService.getVulnerabilityMap(beginDate, endDate);
    }

    //线索统计 新增线索数量
    @OperLog(title = "线索统计新增线索数量",businessType = 0)
    @GetMapping("/cluesStatistics/{beginCreateTime}/{endCreateTime}")
    public ReportVo cluesStatistics(
            @PathVariable("beginCreateTime") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginCreateTime,
            @PathVariable("endCreateTime") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endCreateTime) {
        return reportService.cluesStatisticls(beginCreateTime, endCreateTime);
    }

    //渠道统计 列表展示
    @OperLog(title = "列表展示",businessType = 0)
    @GetMapping("/activityStatisticsList")
    public CourseContractResponseVO<ChannelVo> activityStatistics(ChannelPageDTO dto) {
        return reportService.activityStatistics(dto);
    }

    //渠道数量
    @OperLog(title = "渠道数量",businessType = 0)
    @GetMapping("/chanelStatistics/{beginCreateTime}/{endCreateTime}")
    public List<ChaneCountlVo> chanelStatistics(
            @PathVariable("beginCreateTime") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginCreateTime,
            @PathVariable("endCreateTime") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endCreateTime) {
        List<ChaneCountlVo> chaneCountlVos = reportService.chanelStatistics(beginCreateTime, endCreateTime);
//        return Result.success(chaneCountlVos);
        return chaneCountlVos;
    }

    //活动数量
    @OperLog(title = "活动数量",businessType = 0)
    @GetMapping("/activityStatistics/{beginCreateTime}/{endCreateTime}")
    public List<ChaneActityVo> activityStatisticls(
            @PathVariable("beginCreateTime") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginCreateTime,
            @PathVariable("endCreateTime") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endCreateTime) {
        List<ChaneActityVo> actityVos = reportService.activityStatisticls(beginCreateTime,endCreateTime);
//        return Result.success(actityVos);
        return actityVos;
    }
    
    /**
     * 新增的接口：处理/index请求
     * @param beginCreateTime 开始时间
     * @param endCreateTime 结束时间
     * @param deptId 部门ID
     * @return 指定格式的统计数据
     */
/*    @GetMapping("/index")
    public Result getIndexData(
            @RequestParam("beginCreateTime") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginCreateTime,
            @RequestParam("endCreateTime") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endCreateTime,
            @RequestParam(value = "deptId", required = false) Integer deptId) {
        
        try {
            IndexStatisticsVO data = reportService.getIndexStatistics(beginCreateTime, endCreateTime, deptId);
            return Result.success(data);
        } catch (Exception e) {
            return Result.error("获取首页统计数据失败：" + e.getMessage());
        }
    }*/
}